/**
* 全部进件路由
*/
'use strict';
import detailCtl from './detail'
import applyforCtl from './applyfor'
import approveCtl from './approve'
import intoaCtl from './intoa'
import contractCtl from './contract'
import lendingCtl from './lending'
import orderentryCtrl from './orderentry'   //填写订单-编辑订单控制器
import subsaveokCtrl from './subsaveok' //保存或提交成功控制器
import repayplanCtrl from './repayplan' //保存或提交成功控制器

module.exports = angular.module('app.application', []).config(function($stateProvider) {
    $stateProvider.state('application', { //共用layout
        abstract: true,
        url: '/application',
        templateProvider: function($q) {
            var deferred = $q.defer();
            require.ensure(['../layout.html'], function(require) {
                var template = require('../layout.html');
                deferred.resolve(template);
            }, 'application-tpl');
            return deferred.promise;
        },
        controller: 'applicationCtrl',
        resolve: {
            'app.application': function($q, $ocLazyLoad) {
                var deferred = $q.defer();
                require.ensure(['./index.js'], function() {
                    var mod = require('./index.js');
                    $ocLazyLoad.load({
                        name: 'app.application'
                    });
                    deferred.resolve(mod.controller);
                }, 'application-ctl');
                return deferred.promise;
            }
        }
    }).state('application.applyfor', {//填写申请
        url: '/applyfor',
        views: {
           'content': {
               templateProvider: function($q) {
                console.log('ryy-$q', $q)
                   var deferred = $q.defer();
                   require.ensure(['./applyfor/index.html'], function(require) {
                       var template = require('./applyfor/index.html');
                       deferred.resolve(template);
                   }, 'application.applyfor-tpl');
                   return deferred.promise;
               },
               controller:applyforCtl
           }
        }
    }).state('application.contract', { //合同管理
        url: '/contract?state',
        views: {
            'content': {
                templateProvider: function($q) {
                    var deferred = $q.defer();
                    require.ensure(['./contract/index.html'], function(require) {
                        var template = require('./contract/index.html');
                        deferred.resolve(template);
                    }, 'application.contract-tpl');
                    return deferred.promise;
                },
                controller:contractCtl
            }
        }
    }).state('application.lending', {   //等待还款
        url: '/lending',
        views: {
            'content': {
                templateProvider: function($q) {
                    var deferred = $q.defer();
                    require.ensure(['./lending/index.html'], function(require) {
                        var template = require('./lending/index.html');
                        deferred.resolve(template);
                    }, 'application.lending-tpl');
                    return deferred.promise;
                },
                controller:lendingCtl
            }
        }
    }).state('application.intoa', { //全部进件
        url: '/intoa?state?pageNum',
        views: {
            'content': {
                templateProvider: function($q) {
                    var deferred = $q.defer();
                    require.ensure(['./intoa/index.html'], function(require) {
                        var template = require('./intoa/index.html');
                        deferred.resolve(template);
                    }, 'application.intoa-tpl');
                    return deferred.promise;
                },
                controller:intoaCtl
            }
        }
    }).state('application.detail', { //查看订单
        url: '/intoa/detail?pid?oid?s_id?state?time?',
        views: {
            'content': {
                templateProvider: function($q) {
                    var deferred = $q.defer();
                    require.ensure(['./detail/index.html'], function(require) {
                        var template = require('./detail/index.html');
                        deferred.resolve(template);
                    }, 'application.detail-tpl');
                    return deferred.promise;
                },
                controller:detailCtl
            }
        }
    })
    .state('application.approve', { //审批管理
        url: '/approve',
        views: {
            'content': {
                templateProvider: function($q) {
                    var deferred = $q.defer();
                    require.ensure(['./approve/index.html'], function(require) {
                        var template = require('./approve/index.html');
                        deferred.resolve(template);
                    }, 'application.approve-tpl');
                    return deferred.promise;
                },
                controller:approveCtl
            }
        }
    })
    .state('application.orderentry', {  //录入订单
        url: '/applyfor/orderentry?state?oid?pid',
        views: {
            'content': {
                templateProvider: function($q) {
                    var deferred = $q.defer();
                    require.ensure(['./orderentry/index.html'], function(require) {
                        var template = require('./orderentry/index.html');
                        deferred.resolve(template);
                    }, 'application.orderentry-tpl');
                    return deferred.promise;
                },
                controller:orderentryCtrl
            }
        }
    })
    .state('application.subsaveok', {  //保存或提交成功
        url: '/applyfor/subsaveok?state?pid?oid?opear?msg',
        views: {
            'content': {
                templateProvider: function($q) {
                    var deferred = $q.defer();
                    require.ensure(['./subsaveok/index.html'], function(require) {
                        var template = require('./subsaveok/index.html');
                        deferred.resolve(template);
                    }, 'application.subsaveok-tpl');
                    return deferred.promise;
                },
                controller:subsaveokCtrl
            }
        }
    })
    .state('application.repayplan', {  //保存或提交成功
        url: '/contract/repayplan?state?items',
        views: {
            'content': {
                templateProvider: function($q) {
                    var deferred = $q.defer();
                    require.ensure(['./repayplan/index.html'], function(require) {
                        var template = require('./repayplan/index.html');
                        deferred.resolve(template);
                    }, 'application.repayplan-tpl');
                    return deferred.promise;
                },
                controller:repayplanCtrl
            }
        }
    })
}).name;
